#!/usr/bin/python3
#
# print

import json
import math

# TODO(ddy) : print the comments
def test():
    s = None
    b = None
    print(str(s) + str(b) + "")

if __name__ == '__main__':
    test()


print("name: {}, age: {}.".format("ddy", "28"))
print("name: %s, age: %d." % ("ddy", 28))

print('''
  123
  456
''')

a = 'ABC'
b = a
a = 'XYZ'
print(b)

print("XYZ.startswith X: ", not a.startswith('X'))  # XYZ.startswith X:  False

print("1's ASCII is %d" % ord('1'))
print("代's ASCII is %d" % ord('代'))

# 两个%% 转义为一个%
print("stop num is %d%%" % 18)

dai = ord('代')
print(bin(dai))
print(oct(dai))
print(int(dai))
print(hex(dai))

# 转换为Unicode编码
print(json.dumps("代东洋"))

# 运行结果

'''
name: ddy, age: 28.
name: ddy, age: 28.

  123
  456

ABC
1's ASCII is 49
代's ASCII is 20195
stop num is 18%
0b100111011100011
0o47343
20195
0x4ee3
"\u4ee3\u4e1c\u6d0b"
'''

print('=' * 10)  # ==========

cat = ['fat', 'black', 'loud']
size, color, disposition = cat

print(size, color, disposition)  # fat black loud

print("HELLO".lower())  # hello
print("HELLO".islower())  # False islower 全部小写为True
print("Hello".islower())  # False
print("Hello".isupper())  # False
print("HELLO".isupper())  # True  isupper 全部大写为True
print("Hello".istitle())  # True  istitle 首字母大写，其余小写为True


str_1 = "Bear eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTUwNTY0MDMxLjE0ODM1NzJ9.OEnO3nw_ATqN5UbfIEpRzGDW1lYDrA7wN4AtiimoXGw"
print(str_1.split(".")[1])


print('/'.join(['a']))  # a
print('/'.join(['a', 'b']))  # a/b


# bytes转str
test_str = "123"
test_bytes = test_str.encode('utf-8')
print("bytes string: ", test_bytes)  # bytes string:  b'123'
print("bytes to string: ", test_bytes.decode('utf-8'))  # bytes to string:  123
i = 100
s = '{}'.format(i)
print("number to bytes: ", s.encode('utf-8'))  # number to bytes:  b'100'
print(str(1))

# 截取
ss = "豆邮 (30未读)"
print(ss[4:-3])  # 30

# URL参数分解
params = "v=1&m=2&s=3"
param_dict = {}
for param_pair in params.split('&'):
    print(param_pair)
    key, value = param_pair.split('=')
    param_dict[key] = value
print(param_dict)
if not param_dict.get('version'):
    print("not found version")

#  判断是否以xx开头
xx_string = "xx_abc"
print(xx_string.find('_'))


# 分割